class P2Body {
	private boxBody: p2.Body;
	private _name: string;
	private p2_pos:egret.Point;
	private _rectArr = [];
	public constructor() {

	}

	public create(w:number,h:number,x:number,y:number,world: p2.World,angle:number = 0,dis:egret.DisplayObject){
        var stageHeight:number = GameData.stageHeight;//egret.MainContext.instance.stage.stageHeight;
        var boxShape: p2.Shape = new p2.Box({width: w*GameData.factorc, height: h*GameData.factorc});
        var boxBody: p2.Body = new p2.Body({ mass: 1, position: [(x+w*0.5)*GameData.factorc, (stageHeight - (y+h*0.5))*GameData.factorc]});
        boxBody.addShape(boxShape);
        world.addBody(boxBody);
        boxBody.type = p2.Body.KINEMATIC;
        boxBody.fixedRotation = true;
        boxBody.angle = angle;
        boxBody.displays = [Common.Instance.createBitmapByName('rect')];
        console.log('createBody');
        console.log(x,y,w,h);

		this.p2_pos = new egret.Point();
		this.p2_pos.x = boxBody.position[0];
		this.p2_pos.y = boxBody.position[1];
		
		this._rectArr = [x,y,w,h];
		return boxBody;
    }

	/**
	 * 世界坐标改变
	 */
	public worldPosUpdate(){
		var word_pos:Array<number> = Common.Instance.worldToP2(GameData.worldPos[0],GameData.worldPos[1]);
		this.boxBody.position[0] = this.p2_pos[0] + word_pos[0];
		this.boxBody.position[1] = this.p2_pos[1] + word_pos[1];
	}

	public Update(){
		this.worldPosUpdate();
		if(this.boxBody.displays.length > 0){
			var box: egret.DisplayObject = this.boxBody.displays[0];
			if (box) {
				box.x = this.boxBody.position[0] * GameData.factorx;
				box.y = GameData.stageHeight - this.boxBody.position[1] * GameData.factorx;
				box.rotation = 360 - (this.boxBody.angle + this.boxBody.shapes[0].angle) * 180 / Math.PI;
			}
		}
	}
}